package com.example.project.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.project.entity.Depart;
import com.example.project.mapper.DepartMapper;
import com.example.project.service.DepartService;
import com.example.project.vo.model.PageDto;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;

/**
 * (Depart)表服务实现类
 */
@Service("departService")
public class DepartServiceImpl extends ServiceImpl<DepartMapper, Depart>
        implements DepartService {
    @Resource
    private DepartMapper departMapper;

    @Override
    public Depart queryById(Long id) {
        return this.getBaseMapper().selectById(id);
    }

    @Override
    public PageInfo<Depart> queryAll(PageDto pageDto) {
        PageHelper.startPage(pageDto.getPage(), pageDto.getSize());
        List<Depart> list = this.getBaseMapper().selectList(pageDto.toQueryWrapper());
        return new PageInfo<>(list);
    }

    @Override
    public Depart insert(Depart depart) {
        this.getBaseMapper().insert(depart);
        return depart;
    }

    @Override
    public Depart update(Depart depart) {
        this.getBaseMapper().updateById(depart);
        return this.queryById(depart.getId());
    }

    @Override
    public List<Depart> querryList() {
        return this.getBaseMapper().selectList(null);
    }

    @Override
    public boolean deleteById(Long id) {
        return this.getBaseMapper().deleteById(id) > 0;
    }
}
